<?php
namespace Backend\Controller;
use Think\Controller;
class MainController extends BaseController
{
    public function index() {
        $model =D('Apply');
        $data=$model ->get_apply();

        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
        ));

        $result['apply_count'] =D('Apply')->where(array('user_id' =>$_SESSION['id']))->count();
        $result['force_count'] = D('Apply')->where(array('user_id'=>$_SESSION['id'],'apply_status' =>6))->count();
        $result['ios_count'] = D('Apply')->where(array('user_id'=>$_SESSION['id'],'apply_platform' =>1))->count();
        $result['android_count'] =D('Apply')->where(array('user_id'=>$_SESSION['id'],'apply_platform' =>2))->count();

        $yesterday = date("Y-m-d",strtotime("-1 day"));
        $yesterday_income =D('Price')->field('sum(code_price) as code_price')->where(array('user_id'=>$_SESSION['id'],'date_time' =>$yesterday))->find();
        $result['yesterday_income'] =$yesterday_income['code_price'];

        $gross_income =D('Price')->field('sum(code_price) as code_price')->where(array('user_id'=>$_SESSION['id']))->find();
        $result['gross_income'] =$gross_income['code_price'];

        $cash_withdrawal =D('revenue')->field('sum(cash_withdrawal) as cash')->where(array('user_id'=>$_SESSION['id']))->find();
        $result['cash'] = $cash_withdrawal['cash'];

        $withdrawals =D('revenue')->field('sum(withdrawals) as withdrawals')->where(array('user_id'=>$_SESSION['id']))->find();
        $result['withdrawals'] = $withdrawals['withdrawals'];

        $this->assign('result',$result);
		$this->display('index');
    }

}